📜 [專欄新文章] Gas Efficient Card Drawing in Solidity
✍️ Ping Chen
📥 歡迎投稿: https://medium.com/taipei-ethereum-meetup #徵技術分享文 #使用心得 #教學文 #medium
Assign random numbers as the index of newly minted NFTs
Scenario
The fun of generative art NFT projects depends on randomness. The industry standard is “blind box”, where both the images’ serial number and the NFTs’ index are predetermined but will be shifted randomly when the selling period ends. (They call it “reveal”) This approach effectively solves the randomness issue. However, it also requires buyers to wait until the campaign terminates. What if buyers want to know the exact card right away? We’ll need a reliable onchain card drawing solution.
The creator of Astrogator🐊 isn’t a fan of blind boxes; instead, it thinks unpacking cards right after purchase is more interesting.
Spec
When initializing this NFT contract, the creator will determine the total supply of it. And there will be an iterable function that is randomly picking a number from the remaining pool. The number must be in range and must not collide with any existing ones.
Our top priority is accessibility/gas efficiency. Given that gas cost on Ethereum is damn high nowadays, we need an elegant algorithm to control gas expanse at an acceptable range.
Achieving robust randomness isn’t the primary goal here. We assume there’s no strong financial incentive to cheat, so the RNG isn’t specified. Implementers can bring their own source of randomness that they think is good enough.
Implementation
Overview
The implementation is pretty short and straightforward. Imagine there’s an array that contains all remaining(unsold) cards. When drawIndex() is called, it generates a (uniform) random seed to draw a card from the array, shortens the array, and returns the selected card.
Algorithm
Drawing X cards from a deck with the same X amount of cards is equal to shuffling the deck and dealing them sequentially. It’s not a surprise that our algorithm is similar to random shuffling, and the only difference is turning that classic algo into an interactive version.
A typical random shuffle looks like this: for an array with N elements, you randomly pick a number i in (0,N), swap array[0] and array[i], then choose another number i in (1,N), swap array[1] and array[i], and so on. Eventually, you’ll get a mathematically random array in O(N) time.
So, the concept of our random card dealing is the same. When a user mints a new card, the smart contract picks a number in the array as NFT index, then grabs a number from the tail to fill the vacancy, in order to keep the array continuous.
Tweak
Furthermore, as long as the space of the NFT index is known, we don’t need to declare/initialize an array(which is super gas-intensive). Instead, assume there’s such an array that the n-th element is n, we don’t actually initialize it (so it is an array only contains “0”) until the rule is broken.
For the convenience of explanation, let’s call that mapping cache. If cache[i] is empty, it should be interpreted as i instead of 0. On the other hand, when a number is chosen and used, we’ll need to fill it up with another unused number. An intuitive method is to pick a number from the end of the array, since the length of the array is going to decrease by 1.
By doing so, the gas cost in the worst-case scenario is bound to be constant.
Performance and limitation
Comparing with the normal ascending index NFT minting, our random NFT implementation requires two extra SSTORE and one extra SLOAD, which cost 12600 ~ 27600 (5000+20000+2600) excess gas per token minted.
Theoretically, any instantly generated onchain random number is vulnerable. We can restrict contract interaction to mitigate risk. The mitigation is far from perfect, but it is the tradeoff that we have to accept.
ping.eth
Gas Efficient Card Drawing in Solidity was originally published in Taipei Ethereum Meetup on Medium, where people are continuing the conversation by highlighting and responding to this story.
👏 歡迎轉載分享鼓掌
同時也有15部Youtube影片,追蹤數超過5萬的網紅Kohki Yamaguchi,也在其Youtube影片中提到,So I took the Xperia 1 III for a full day of photography, testing out every lens and every lighting condition I could think of. I'm pretty surprised o...
「pretty images」的推薦目錄:
- 關於pretty images 在 Taipei Ethereum Meetup Facebook 的最讚貼文
- 關於pretty images 在 Facebook 的最佳解答
- 關於pretty images 在 Facebook 的精選貼文
- 關於pretty images 在 Kohki Yamaguchi Youtube 的最讚貼文
- 關於pretty images 在 FERNTUBE (Fernanda Ly) Youtube 的最佳解答
- 關於pretty images 在 Daphne Iking Youtube 的最佳解答
- 關於pretty images 在 240 Best MOST BEAUTIFUL PICTURES ideas - Pinterest 的評價
- 關於pretty images 在 Pretty Pictures Photography - Facebook 的評價
- 關於pretty images 在 Bryce Savage - Pretty Pictures (Lyrics) - YouTube 的評價
- 關於pretty images 在 CSS, JS and images do not display with pretty url 的評價
pretty images 在 Facebook 的最佳解答
MELACELLS - Bộ sản phẩm hỗ trợ mờ nám từ Tế bào gốc thực vật - PRETTY SKIN Hàn Quốc tại Ốc mama
Prettyskin Vietnam
Video by Nee Images - Chụp Ảnh Cho Bé & Gia Đình
pretty images 在 Facebook 的精選貼文
🤱Relishing in My proud 1 year 🐄 moment.
Over 365 days & nights of breastfeeding this little one, I’m hoping that I can still persist on for another year, just liked how I did with her brothers 💪🏻 must gambette nei coz it’s the 3rd time already as it’s over a 6 years of 24/7 milk buffet for the kids, not easy but I made it and really proud and enjoying the bonding a lot 🙏🙏🙏😚, oh wells what to do ~
#stickymama
#doingmybest #buildherimmunity
And being able to twin with her is my dream come true, especially with @jumpeatcry nursing friendly dresses & tops’ I’m milking as much as I can while she’s a baby, I know next time you won’t do so with mummy Liao right 😝
Sorry boys, let mummy enjoy these sweet mummy & daughter bonding for a while 🙏 ☺️ tho I still love twinning with you two too!
Here’s more images from yesterday ❤️🎂🥳 coz the set up is really too pretty and we have more cutiee pics to post #dontmindme 😍
Regards to our small & simple party, We didn’t want a cake too large so we went with a standard cake which we can feed the kids and finished easily. Desserts we ordered for our sweet neighbours who been very nice to us since we moved last December.
Now, another month to go for Noah’s big 7! (In case you are new here, my kids birthday nicely land on 30th of may, june, July, all natural birth) 😂 not sure if it’s a good or bad thing. At least no need to test my memory 🤣
SetUp: @threecheersparty
Cake & Desserts: @sarahsloft
Baby headband: @lilchubbsj_
#familystaysg #sgfamily #birthdaysetup #balloonsdecor #birthdaycake #birthdaygirl #mummysgirl #daddysgirl #sgbaby #sgbabies #cutebaby #twinningwithmommy #twinningwithmom #dressupdaily #sglookbook #singapore #desserttable #sgdesserts #sgcakeshop #floraltheme #birthdayparty #firstbirthday #mytribe❤
pretty images 在 Kohki Yamaguchi Youtube 的最讚貼文
So I took the Xperia 1 III for a full day of photography, testing out every lens and every lighting condition I could think of. I'm pretty surprised on how well it handled low light.
I hope you all enjoyed the video and let me know if this is a phone you would consider getting!
*日本の皆さん、設定から日本語字幕を表示できます。字幕ONにしてご覧下さい。
よろしくお願いします!
Heres a few sample images for download:
https://drive.google.com/file/d/19aecHXPVi_9K9muQIh4akhdvitZraB8q/view?usp=sharing
These are non edited jpeg files taken with the Xperia 1 III
*Only to be used for educational purposes.
All photos in THIS video was edited. Just basic W/B and exposure.
I made sure to not alter colors so you will not see much color difference from the original.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Check the official Sony channel for more Xperia 1 III related videos: https://www.youtube.com/user/sonyxperia
My Gear: https://www.amazon.com/shop/kohki
All photographs in this episode was edited using the 'Signature' Preset pack available here:
https://www.kohkipresets.com/product-page/Signature-Preset-Pack-By-Kohki
My Instagram: https://www.instagram.com/Kohki
My Store: https://www.kohkipresets.com
My Website: https://www.kohkicontent.com
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
#SonyXperia1III #Xperia #Photography
Chapters:
0:00 intro
0:34 Location 1 | Tokyo Teleport sta.
1:43 Location 2 | Team Lab Borderless
3:35 Location 3 | Rainbow Bridge
5:17 Location 4 | Asakusa
8:12 Location 5 | Skytree
9:58 Location 6 | Bridge
10:46 Location 7 | Shinjuku
12:11 end
pretty images 在 FERNTUBE (Fernanda Ly) Youtube 的最佳解答
(Giveaway info is at the bottom)
Today we celebrate 10k subs with a Vivienne Westwood sample sale video that I've been meaning to post 🌟
I may or may not have been waiting for this milestone in order to do so 👀
I previously asked if everyone was open to a giveaway and I'm so excited to hold one now! The names of the prizes are also below in case you want to buy them yourself hahaha
Fun fact: The night before was when I dislocated my knee, but as a big fan and collector of VW I couldn't miss this sale. Pretty sure standing in line is what made my knee worse.... The few weeks in an immobiliser was worth it for this 🤗
I've really enjoyed being on YouTube, so thank you for your support thus far! Tbh I wasn't expecting to keep at it for so long lol
It's been fun learning how to edit videos and images too. I'm aware there are many things I could improve on and things I could nitpick at, but I feel like I've come a long way from my first upload 9 months ago 🥸
Again, thank you so much for your continued support in watching, commenting, and liking my videos. It means the world to me ❤
ーーーーーーー
#ferntube #viviennewestwood #giveaway
✩ Instagram: @warukatta
✩ Email: ferntube22@gmail.com
Please contact my agencies in regards to model work
ーーーーーーー
✩ Songs:
Waves - Fiji Blue (https://thmatc.co/?l=518C9DB2)
Lovely Day - VirgoZilla Beatz (https://thmatc.co/?l=184FE7FC/)
✩ Subtitle file: (https://drive.google.com/file/d/1GHCjMd_s-ciGbpcVa_p1W8XlnsnA0O6s/view?usp=sharing)
*** As Youtube has unfortunately discontinued community contributions, here is the script for anyone still willing to do subs for other languages. If you replace the english text with your language and email me the file, I'll be more than happy to upload it for everyone to see. Thank you for your helpful contributions until now!
✩ FTC: This giveaway is not sponsored by Vivienne Westwood, YouTube, nor any other company and all moneys spent is my own.
ーーーーーーー
Ferntube's 10k Subscriber Giveaway ❤️❤️❤️
Comment to win a pair of Vivienne Westwood earrings in celebration of 10k subs!
I want to share my happiness by giving two(!) subscribers the chance to win a pair of earrings each!
🌎 Giveaway is open worldwide 🌎
PRIZES:
✩✩ Vivienne Westwood 'Sorada' Orb Earrings (Crystal on Rhodium) ✩✩
✩✩ Vivienne Westwood 'Rosemary' Small Earrings (Brass) ✩✩
HOW TO WIN:
Leave a comment on this video
That's it
Please be sure you're subscribed to my YouTube (I'll be checking!)
If you are under 18 years old, please have parental permission before commenting.
Only one entry per person; multiple entries/ comments will not be counted.
I'll use a random number generator to choose two winning comments so everything stays fair ❤️
Giveaway begins 02/03/2021 upon upload and closes midnight (Eastern Standard Time) of 22/03/2021
Winners must message me within 48 hours of contact to claim prizes, if not, I will have the rng choose another comment.
pretty images 在 Daphne Iking Youtube 的最佳解答
The kids and I decided to create our very own indoor #IkingAzmi Botanical Garden learning park, seeing that Iman has suddenly developed an interest in botany.
We used the HP DeskJet Plus Ink Advantage 6075 Printer to bring learning to life! With HP Smart app, we can print and research materials online and I liked that we could scan images from magazines and photos, and print them right away.
Our botanical garden looks so pretty, I’m leaving it alone. I wanted to spruce up the living area, so now it’s done. Yay!
Now is your chance to win a HP DeskJet Plus Ink Advantage 6075 Printer! Just follow these easy steps:
1. Recreate your favourite outdoor park using materials from HP’s Print & Play website
2. Snap a picture with your child
3. Upload the image and share your description of your creation on the contest page
Contests run all the way till 30 November!
Find out more on the Contest Page:
https://hpmalaysia.com/paperparks
Here’s the link to the Print & Play website:
https://www8.hp.com/my/en/printers/printandplay/index.html
Good luck!
Thanks for watching and please do not forget to subscribe!
Also follow me on my other social media channels:
Instagram
https://www.instagram.com/daphneiking/
Facebook
https://www.facebook.com/daphneiking/
Twitter
https://twitter.com/DaphCLPT
If you also need my profile and showreel, please visit:
joelebosi.wix.com/bedifulstory
Thanks for watching and please do not forget to subscribe!
Also follow me on my other social media channels:
Instagram
https://www.instagram.com/daphneiking/
Facebook
https://www.facebook.com/daphneiking/
Twitter
https://twitter.com/DaphCLPT
If you also need my profile and showreel, please visit:
joelebosi.wix.com/bedifulstory
pretty images 在 Pretty Pictures Photography - Facebook 的推薦與評價
Pretty Pictures Photography, Bangalore, India. 11203 likes · 28 talking about this. Bangalore based, Internationally certified Newborn, Maternity & Baby... ... <看更多>
pretty images 在 Bryce Savage - Pretty Pictures (Lyrics) - YouTube 的推薦與評價
stream: ffm.to/brycesavage Bryce Savage - Pretty Pictures (Lyrics) Help us reach 500000 subscribers! ... <看更多>
pretty images 在 240 Best MOST BEAUTIFUL PICTURES ideas - Pinterest 的推薦與評價
Oct 7, 2021 - Explore SARIE STYGER's board "MOST BEAUTIFUL PICTURES" on Pinterest. See more ideas about beautiful nature, scenery, beautiful pictures. ... <看更多>